<template>
  <div class="page-template-default page page-id-4987 wp-embed-responsive
  exam-apo-two exam-style-radius nice-style-shadow nice-style-border
  lights-mode" style="background: #F6F6F7;">
    <remote-css href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"></remote-css>
    <div class="exam-apo-sign d-flex flex-fill align-items-lg-center h-v ">
      <main class="exam-sign-main ">
        <div class="exam-sign-inner shadow-2x">
          <div class="row no-gutters">
            <div class="col-12 col-md-12 col-lg-6 col-xl-7 order-1">
              <div class="sign-cover d-flex flex-column bg-secondary bg-img bg-cover bg-dark w-100 h-100 p-4 p-md-5 p-lg-4"
                style="background-image: url(https://img.smitish.com/wp-content/uploads/20200922133511.png);">
                <h1 class="smitish-sign-logo mx-auto mx-lg-2 my-auto my-lg-2">
                  <a title="Exam Cloud Pro" class="d-block"><img src="https://img.smitish.com/wp-content/uploads/20201031110238.png" /></a>
                </h1>
              </div>
            </div>
            <div class="col-12 col-md-12 col-lg-6 col-xl-5 order-2">
              <div class="sign-content bg-white mt-n4 mt-lg-0 mb-4 mb-lg-0">
                <a class="offiaccount-sign exam-sign-erweima"></a>
                <div class="sign-body">
                  <div class="sign-header text-font h2 text-center mb-1 mb-md-1"
                    style="font-weight: 900;font-size: 2.2rem;margin-top: 20px;">
                    注册账号
                  </div>
                  <el-form id="sign-form" :model="ruleForm" :rules="rules" ref="ruleForm" class="mt-4" style="display: block;">
                    <div class="form-group">
                      <input type="text" class="form-control form-control-lg" style="font-size: 1.2rem;font-weight: 800;"
                        v-model="ruleForm.username" placeholder="用户名" />
                    </div>
                    <div class="form-group">
                      <input type="password" class="form-control form-control-lg" style="font-size: 1.2rem;font-weight: 800;"
                        v-model="ruleForm.password" placeholder="密码" />
                    </div>
                    <div class="form-group">
                      <input type="password" class="form-control form-control-lg" style="font-size: 1.2rem;font-weight: 800;"
                        v-model="ruleForm.password2" placeholder="确认密码" />
                    </div>
                    <div class="form-group">
                      <input type="email" class="form-control form-control-lg" style="font-size: 1.2rem;font-weight: 800;"
                        v-model="ruleForm.email" placeholder="邮箱" />
                    </div>
                    <div class="form-aciton mt-5">
                      <button type="button" class="mt-4 btn btn-primary btn-block " @click="RegisterAccount('ruleForm')">
                        <span style="font-size: 1.5rem;font-weight: 800;">注册账号</span>
                      </button>
                    </div>
                  </el-form>
                  <div class="ext-muted text-sm text-center mt-2 mt-md-3 ">
                    已经有账号了？
                    <span><a @click="toLogin" style="color:#000">立即登录</a></span>
                  </div>
                  <div class="pt-5 pt-md-5 ext-muted text-sm text-center" style="padding-top: 40px;">
                    <!-- <span>Powered by © 2019-2020 SMITISH.COM</span> -->
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </main>
    </div>
  </div>
</template>

<script>
export default {
  components: {
    'remote-css': {
      render (createElement) {
        return createElement('link', { attrs: { rel: 'stylesheet', href: this.href } });
      },
      props: {
        href: { type: String, required: true },
      },
    },
    'remote-js': {
      render (createElement) {
        return createElement('script', { attrs: { type: 'text/javascript', src: this.src } });
      },
      props: {
        src: { type: String, required: true },
      },
    },
  },
  name: "Register",
  data () {
    return {
      ruleForm: {
        username: 'Smitish',
        password: '111111',
        password2: '111111',
        email: "1322175819@qq.com"
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'change' }
        ],
        password2: [
          { required: true, message: '请确认密码', trigger: 'change' }
        ],
        email: [
          { required: true, message: '请输入邮箱', trigger: 'change' }
        ]
      }
    };
  },
  methods: {
    toLogin () {
      this.$router.push({
        path: `/Login`
      });
    },
    checkEmail () {
      var email = this.ruleForm.email;
      var Reg = /^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/;

      if (Reg.test(email)) {
        return true;
      } else {
        return false;
      }
    },
    RegisterAccount (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const _this = this
          // 判断用户名是否为空
          if (this.ruleForm.username == "") {
            this.$message.error('用户名不能为空', { duration: 3 * 1000 })
            return;
          } else if (this.ruleForm.password == "" || this.ruleForm.password2 == "") {
            this.$message.error('密码不能为空', { duration: 3 * 1000 })
            return;
          } else if (this.ruleForm.email == "") {
            this.$message.error('邮箱不能为空', { duration: 3 * 1000 })
            return;
          } else {
            if (!this.checkEmail()) {
              this.$message.error('邮箱格式错误', { duration: 3 * 1000 })
              return;
            } else if (this.ruleForm.username.length < 6 || this.ruleForm.username > 16) {
              this.$message.error('用户名长度只能为6到15个字符', { duration: 3 * 1000 })
              return;
            } else if (this.ruleForm.password != this.ruleForm.password2) {
              this.$message.error('两次密码不相符', { duration: 3 * 1000 })
              return;
            } else {
              // 通过前端验证
              this.$axios.post('/register', this.ruleForm).then(res => {
                console.log(res)
                if (res.data.code == 200) {
                  this.$message.success(res.data.msg, { duration: 3 * 1000 })
                  this.$router.push("/Login")
                } else {
                  this.$message.error(res.data.msg, { duration: 3 * 1000 })
                }
              })
            }
          }
        } else {
          console.log('error submit!!');
          // this.$store.commit("REMOVE_INFO");
          return false;
        }
      });
    },
  }
};
</script>

<style scoped>
/* @import url("https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"); */

.h-v {
  min-height: 100vh;
}

.exam-sign-main {
  width: 100%;
  margin: 0 auto;
  position: relative;
}

.exam-sign-inner {
  position: relative;
  overflow: hidden;
  -webkit-box-shadow: 0px 0px 20px 0px rgba(158, 158, 158, 0.1);
  box-shadow: 0px 0px 20px 0px rgba(158, 158, 158, 0.1);
}

.exam-sign-logo {
  max-width: 160px;
}

.exam-sign-inner .sign-content {
  padding: 100px 80px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-box-flex: 1;
  -ms-flex: 1 1 auto;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
}

.exam-sign-inner .sign-body {
  -webkit-box-flex: 1;
  -ms-flex: 1 1 auto;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  max-width: 420px;
  margin: 0 auto;
  width: 100%;
}

.exam-sign-inner .sige-getpwd {
  margin: auto;
  -webkit-flex: none;
  -webkit-box-flex: 0;
  -ms-flex: none;
  flex: none;
}

@media (min-width: 1200px) {
  .exam-sign-main {
    max-width: 1140px;
    height: 100%;
  }

  .exam-sign-inner .sign-content {
    height: 66vh;
    max-height: 680px;
  }
}

@media (min-width: 992px) and (max-width: 1199.98px) {
  .exam-sign-main {
    max-width: 960px;
    height: 100%;
  }

  .exam-sign-inner .sign-content {
    padding: 100px 60px;
    height: 66vh;
    max-height: 580px;
  }
}

@media (max-width: 991.98px) {
  .exam-apo-sign .sign-cover {
    min-height: 33.333vh;
  }

  .exam-apo-sign .sign-content {
    position: relative;
    border-radius: 3px;
    -webkit-box-shadow: 0px 0px 35px 15px rgba(158, 158, 158, 0.25);
    box-shadow: 0px 0px 35px 15px rgba(158, 158, 158, 0.25);
  }

  .exam-sign-inner {
    background-color: #f6f6f7;
    border-radius: 0;
    -webkit-box-shadow: none;
    box-shadow: none;
    height: 100%;
  }

  .exam-sign-inner.rounded {
    border-radius: 0 !important;
  }

  .exam-sign-inner .sign-content {
    padding: 50px 40px;
    margin-left: 30px;
    margin-right: 30px;
  }
}

@media (min-width: 768px) and (max-width: 991.98px) {
  .exam-sign-inner .sign-content {
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
  }
}

@media (max-width: 767.98px) {
  .exam-apo-sign .sign-cover {
    min-height: 45vh;
  }

  .exam-sign-inner .sign-content {
    margin-left: 20px;
    margin-right: 20px;
    padding: 40px 20px;
  }
}

.lights-mode .shadow,
.lights-mode .shadow-2x {
  -webkit-box-shadow: none !important;
  box-shadow: none !important;
}

.exam-sign-inner {
  position: relative;
  overflow: hidden;
  -webkit-box-shadow: 0px 0px 20px 0px rgba(158, 158, 158, 0.1);
  box-shadow: 0px 0px 20px 0px rgba(158, 158, 158, 0.1);
}

.exam-apo-two .no-gutters > .col,
.exam-apo-two .no-gutters > [class*="col-"] {
  padding-left: 0;
  padding-right: 0;
}

.bg-cover {
  -ms-background-size: cover;
  background-size: cover;
  background-repeat: no-repeat;
}

.bg-img {
  background-size: cover;
  background-position: 50% 50%;
  background-repeat: no-repeat;
}

.exam-sign-logo {
  max-width: 160px;
}

.lights-mode,
.lights-mode a:not(.btn) {
  color: #999;
}

a:link,
a:visited {
  text-decoration: none;
}

a img {
  border: 0 none;
}

img {
  max-width: 100%;
  height: auto;
  position: relative;
}

.exam-sign-inner .sign-content {
  padding: 100px 80px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-box-flex: 1;
  -ms-flex: 1 1 auto;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
}

.lights-mode .bg-white {
  background-color: #21242b !important;
}

.lights-mode .exam-sign-erweima {
  background-image: url();
}

a:link,
a:visited {
  text-decoration: none;
}

.exam-sign-erweima {
  position: absolute;
  right: 5px;
  top: 5px;
  width: 45px;
  height: 45px;
  background-image: url();
  background-position: top center;
  background-repeat: no-repeat;
  background-size: contain;
}

a {
  color: #161e27;
  -webkit-transition: all 0.3s ease;
  -o-transition: all 0.3s ease;
  transition: all 0.3s ease;
  cursor: pointer;
}

.exam-sign-inner .sign-body {
  -webkit-box-flex: 1;
  -ms-flex: 1 1 auto;
  -webkit-flex: 1 1 auto;
  flex: 1 1 auto;
  max-width: 420px;
  margin: 0 auto;
  width: 100%;
}

h2,
.h2 {
  font-size: 2.25rem;
  color: #21242b;
}

.h1,
.h2,
.h3,
.h4,
.h5,
.h6,
h1,
h2,
h3,
h4,
h5,
h6 {
  margin-bottom: 0;
  line-height: 1.5;
}

body,
input,
button,
select,
optgroup,
option,
textarea,
blockquote,
dd,
dl,
figure,
form,
pre,
.h1,
.h2,
.h3,
.h4,
.h5,
.h6,
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: "SF Pro SC", "SF Pro Text", "SF Pro Icons", PingFang SC,
    Lantinghei SC, Microsoft Yahei, Hiragino Sans GB, Microsoft Sans Serif,
    WenQuanYi Micro Hei, sans-serif;
  -moz-osx-font-smoothing: grayscale;
  -webkit-font-smoothing: antialiased;
}

.lights-mode .btn-light {
  color: #969aa7;
  background-color: #2e313a;
  border-color: #2e313a;
}

.exam-style-radius .btn-circle {
  border-radius: 50%;
}

.exam-style-radius .nav-links > span,
.exam-style-radius .nav-links > a,
.exam-style-radius .btn,
.exam-style-radius .form-control {
  border-radius: 5px;
}

.btn-icon.btn-lg {
  width: 2.875rem;
  height: 2.875rem;
  font-size: 1.375rem;
}

.btn-icon span {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
}

.exam-apo.text-lg {
  font-size: 1.5rem !important;
}

.exam-apo {
  line-height: 1;
  display: inline-block;
  vertical-align: middle;
}

.exam-apo {
  font-family: "exam-apo" !important;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  vertical-align: middle;
}

.lights-mode .form-control {
  /* border: 2px solid rgb(121, 167, 252); */

  border: none;
  border-bottom: 2px solid rgb(121, 167, 252);
  border-radius: 0;
  background-color: #fff !important;
  color: #333;
  -webkit-box-shadow: none;
  box-shadow: none;
}

.form-control-lg {
  font-size: 0.9375rem;
  line-height: 1.5;
  padding: 0.75rem 1rem;
  height: calc(1.5em + 1.625rem + 2px);
}

.lights-mode .text-muted {
  color: #969aa7 !important;
}

.exam-apo {
  line-height: 1;
  display: inline-block;
  vertical-align: middle;
}

.btn-group-lg > .btn,
.btn-lg {
  padding: 0.75rem 2.5rem;
  font-size: 1rem;
}

.lights-mode .bg-white {
  background-color: #fff !important;
}

.lights-mode .exam-time-main,
.lights-mode.exam-apo-two {
  background-color: #fafafa;
}

.exam-apo-two,
.exam-time-main,
.tax-weibo_topic {
  background-color: #f6f6f7;
}
.smitish-sign-logo {
  max-width: 260px;
}
</style>